package org.com.myfb.action;

import java.util.Date;
import java.util.List;

import org.com.myfb.dao.PersonDaoInter;
import org.com.myfb.model.Person;
import org.com.myfb.model.Students;
import org.com.myfb.service.PersonServiceInter;

import com.opensymphony.xwork2.ActionSupport;

public class AddStudentAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private PersonDaoInter personDaoImpl;
	private PersonServiceInter personServiceImpl;
	private String num;
	private String psw;
	private int sid;
	private String sname;
	private String ssex;
	private String sclass;
	private Date sstarttime;
	private int sxuezhi;
	private String data;
	
	
	public String getData() {
		return data;
	}
	public void setData(String data) {
		this.data = data;
	}
	public PersonDaoInter getPersonDaoImpl() {
		return personDaoImpl;
	}
	public void setPersonDaoImpl(PersonDaoInter personDaoImpl) {
		this.personDaoImpl = personDaoImpl;
	}
	public PersonServiceInter getPersonServiceImpl() {
		return personServiceImpl;
	}
	public void setPersonServiceImpl(PersonServiceInter personServiceImpl) {
		this.personServiceImpl = personServiceImpl;
	}
	public String getNum() {
		return num;
	}
	public void setNum(String num) {
		this.num = num;
	}
	public String getPsw() {
		return psw;
	}
	public void setPsw(String psw) {
		this.psw = psw;
	}
	public int getSid() {
		return sid;
	}
	public void setSid(int sid) {
		this.sid = sid;
	}
	public String getSname() {
		return sname;
	}
	public void setSname(String sname) {
		this.sname = sname;
	}
	public String getSsex() {
		return ssex;
	}
	public void setSsex(String ssex) {
		this.ssex = ssex;
	}
	public String getSclass() {
		return sclass;
	}
	public void setSclass(String sclass) {
		this.sclass = sclass;
	}
	public Date getSstarttime() {
		return sstarttime;
	}
	public void setSstarttime(Date sstarttime) {
		this.sstarttime = sstarttime;
	}
	public int getSxuezhi() {
		return sxuezhi;
	}
	public void setSxuezhi(int sxuezhi) {
		this.sxuezhi = sxuezhi;
	}
	
	public String execute(){
	System.out.println("添加学生的*******5");
		Person person = new Person();
		System.out.println("添加学生的*******6");
		Students student= new Students();
		System.out.println("添加学生的*******7");
		String where = " num = " + "'" + this.getNum() + "'";
		System.out.println("添加学生的*******8");
		List<Person> persons = this.getPersonDaoImpl().findList(Person.class, where);
		System.out.println("添加学生的*******9");
		if(persons.size()>0){
			System.out.println("添加学生的*******10");
			this.setData("[{\"message\":\"2\"}]");
			System.out.println("添加学生的*******11");
			return ERROR;
		}else{
			this.getPersonServiceImpl().addStudent(person,student,this.getNum(),this.getPsw(),this.getSid(),this.getSname(),this.getSsex(),this.getSclass(),this.getSstarttime(),this.getSxuezhi());
			this.setData("[{\"message\":\"1\"}]");
			return SUCCESS;
		}
	}
}
